﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using InnovaApp.Portals.MVC4Portal.Models;
using INNOVACALL.Framework.Common;
using InnovaApp.Layers.ResourcesLayer.Properties;
using INNOVACALL.Framework.Common.MVCHelpers;
using InnovaApp.Layers.DataLayer;
using INNOVACALL.Framework.Common.CodeFormatting;
using INNOVACALL.Framework.Common.Models;

namespace InnovaApp.Portals.MVC4Portal.Controllers
{
	public class DiagramsController : _Controllers_Base<DiagramsModel>
	{
		protected override void Initialize(System.Web.Routing.RequestContext requestContext)
		{
			base.eMethodBase = "InnovaApp.Portals.InnovaAppFrontOfficePortal.Controllers.DiagramsController";
			base.specificCssCollection = new string[] { "_FormCommon.css", "Views/Diagrams.css", "ClientComponents/CodeFormatting/csharp.css", "ClientComponents/KendoUI/kendo.common.min.css", "ClientComponents/KendoUI/kendo.blueopal.min.css" };
			base.specificJSCollection = null;
			base.dynamicJSCollection = new string[] { "/ScriptsG/inoDiagramsDynamic.js" };
			base.specificJqueryJSCollection = new string[] { "ClientComponents/jquery/ddpowerzoomer.js", "ClientComponents/KendoUI/kendo.web.min.js", "InnovacallJS/Diagrams/Diagrams.js" };
            base.jsVariables = null;
			base.externalCSS = null;
			base.Meta.Add(enMeta.Description, Resources.View_Diagrams_Meta_Description);
			base.Meta.Add(enMeta.Keywords, Resources.View_Diagrams_OrderWithDetails_Meta_Keywords);
			base.Meta.Add(enMeta.Subject, Resources.View_Diagrams_OrderWithDetails_Meta_Subject);

			base.Initialize(requestContext);
		}

		[HttpGet, Authorize, CacheManager(enCacheMode.NoCache)] //Manage your cache
		public ActionResult PDM(string Id)
		{
			//NEVER USES VIEW BAG AGAIN !
			//ViewBag.Message = "Modify this template to kick-start your ASP.NET MVC application.";
			{
				using (DataRepositories _context = new DataRepositories())
				{
					base.InitView(
						Resources.View_Diagrams_PageTitle,
						Resources.View_Diagrams_PageMessage,
						specificCssCollection,
						specificJSCollection,
						dynamicJSCollection,
						specificJqueryJSCollection,
                        jsVariables,
						externalCSS,
						Meta,
						_context,
						true);

					string packageName = Id.Substring(0, Id.Length - 7);

					ContentData._Meta[enMeta.Description] = string.Format(ContentData._Meta[enMeta.Description], packageName);
					ContentData._Meta[enMeta.Subject] = string.Format(ContentData._Meta[enMeta.Subject], packageName);
					ContentData._PageTitle = string.Format(ContentData._PageTitle, packageName);

					ContentData.DiagramImageUrl = string.Format("/Images/PDM/{0}", Id);
					ContentData.DiagramImageAlt = packageName;

					FillInvolvedCode();	
				}
				return View(ContentData);
			}
		}

		[HttpGet, Authorize, CacheManager(enCacheMode.NoCache)] //Manage your cache
		public ActionResult CD(string Id)
		{
			//NEVER USES VIEW BAG AGAIN !
			//ViewBag.Message = "Modify this template to kick-start your ASP.NET MVC application.";
			{
				using (DataRepositories _context = new DataRepositories())
				{
					base.InitView(
						Resources.View_Diagrams_PageTitle,
						Resources.View_Diagrams_PageMessage,
						specificCssCollection,
						specificJSCollection,
						dynamicJSCollection,
						specificJqueryJSCollection,
                        jsVariables,
						externalCSS,
						Meta,
						_context,
						true);

					string packageName = Id.Substring(0, Id.Length - 7);

					ContentData._Meta[enMeta.Description] = string.Format(ContentData._Meta[enMeta.Description], packageName);
					ContentData._Meta[enMeta.Subject] = string.Format(ContentData._Meta[enMeta.Subject], packageName);
					ContentData._PageTitle = string.Format(ContentData._PageTitle, packageName);

					ContentData.DiagramImageUrl = string.Format("/Images/CD/{0}", Id);
					ContentData.DiagramImageAlt = packageName;

					FillInvolvedCode();

				}
				return View(ContentData);
			}
		}

		private void FillInvolvedCode()
		{
			ContentData.InvolvedCode = new InvolvedCodeModel();
			ContentData.InvolvedCode.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Html, TabStripName = "View", TabStripContent = "/Views/Diagrams/CD.cshtml" });
			ContentData.InvolvedCode.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.cSharp, TabStripName = "Controller", TabStripContent = "/Controllers/DiagramsController.cs" });
			ContentData.InvolvedCode.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.cSharp, TabStripName = "Model", TabStripContent = "/Models/DiagramsModel.cs" });
			ContentData.InvolvedCode.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Javascript, TabStripName = "View JS", TabStripContent = "/Scripts/InnovacallJS/Diagrams/Diagrams.js" });
			ContentData.InvolvedCode.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.GeneratedJavascript, TabStripName = "View Generated JS", TabStripContent = "/ScriptsG/inoDiagramsDynamic.js" });
			RenderCodeFiles(ContentData.InvolvedCode);
		}

	}
}
